package com.quanquan.parking.ketop.repository;

import com.quanquan.parking.ketop.entity.ParkingRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName:ParkingRecordRepository
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/9/11 11:15
 * @Version 1.0
 */
public interface ParkingRecordRepository extends JpaRepository<ParkingRecord,String>, JpaSpecificationExecutor<ParkingRecord> {


    /**
     * 查找当前订单
     *
     * @param orderNo
     * @return
     */
    @Query(value = "select * from oo_parking_record where order_no = ?1 order by pay_time desc",nativeQuery = true)
    List<ParkingRecord> findByOrderNo(String orderNo);

    /**
     * 查找停车记录（成功支付）
     *
     * @param userId
     * @return
     */
    @Query(value = "select * from oo_parking_record where user_id = ?1 and status = 1 order by pay_time desc limit ?2,?3",nativeQuery = true)
    List<ParkingRecord> findByUserIdAndStatus(String userId, Integer count, Integer size);


    /**
     * 查找停车记录（成功支付）
     *
     * @param userId
     * @return
     */
    @Query(value = "select * from oo_parking_record where user_id = ?1 and status = 1 and user_discount = 1 and TO_DAYS(create_time) = TO_DAYS(NOW())",nativeQuery = true)
    List<ParkingRecord> findByUserIdAndTime(String userId);
}
